package _1_LabelAndButton;

import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicToggleButtonUI;

public class ImageButtonUI extends BasicToggleButtonUI {

    public ImageButtonUI() {

    }
    
    public void paint(Graphics g, JComponent c) {
        AbstractButton b = (AbstractButton) c;
        paintIcon(g, b, null);
    }

    protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
        ButtonModel model = b.getModel();
        Icon icon = null;

        if (model.isPressed() && model.isArmed()) {
            icon = b.getPressedIcon();
        } else if (/*b.hasFocus() || */(b.isRolloverEnabled() && model.isRollover())) {
            icon = b.getSelectedIcon();
        }

        if (icon == null) {
            icon = b.getIcon();
        }

//        icon.paintIcon(b, g, iconRect.x, iconRect.y);
        icon.paintIcon(b, g, 0, 0);
    }
}
